<?php
/** 需要被代理的类 */
interface RealityInterface
{
    public function setContent($content);
    public function output();
}
class Reality implements RealityInterface
{
    public $content="";
    public function setContent($content)
    {
        $this->content = $content;
    }
    public function output()
    {
        echo $this->content . "\r\n";
    }
}

/**
 * @property string $content
 */
class Proxy implements RealityInterface
{
    /** @return Reality */
    protected function getReality()
    {
        if(!$this->_reality){
            $this->_reality = new Reality;
        }
        return $this->_reality;
    }
    public function setContent($content)
    {
        return $this->getReality()->setContent($content);
    }
    public function output()
    {
        return $this->getReality()->output();
    }
    public function __get($name)
    {
        return $this->getReality()->$name;
    }
    public function __call($name, $arguments)
    {
        return call_user_func_array([$this->getReality(), $name], $arguments);
    }
}

$obj = new Proxy;
$obj->setContent("hello world");
$obj->output();
